package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.Exceptions.ClientExistsException;
import com.acme.bankapp.domain.Exceptions.OverDraftLimitExceededException;
import com.acme.bankapp.domain.bank.AbstractAccount;
import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.bank.CheckingAccount;
import com.acme.bankapp.domain.bank.Client;
import com.acme.bankapp.domain.bank.Gender;
import com.acme.bankapp.domain.bank.SavingAccount;

public class BankApplication {	
	
	public static void modifyBank(Bank bank) {
		try{
			Client bank_client1, bank_client2;
			bank_client1 = bank.getClient(0);
			bank_client2 = bank.getClient(0);
			bank_client1.getAccount(0).withdraw(1250);
			bank_client2.getAccount(0).deposit(345);
		}
		catch (IllegalArgumentException e) {
			System.out.println("The Exception" + e.getMessage() + " has occured");
		}
		catch (OverDraftLimitExceededException e) {
			System.out.println("The Exception OverDraftLimitExceededException has occured");
			System.out.println("request exceeded balance on " + e.getAmount());
		}
	}
	
	public static void printBalance(Bank bank) {		
		int num = bank.getNumClients();
		Client client1;	
		AbstractAccount account1;
		for (int i = 0; i < num; i++) {
			client1 = bank.getClient(i);
			account1 = client1.getAccount(0);
			System.out.println("Balance of client " + i + " is " + account1.getBalance());
			}
		}

	
	public static void main(String[] args) {
		
		BankService bs = new BankService();
		Bank SberBank = new Bank();		
		
		Client client1 = new Client (new CheckingAccount(), 10, "Smith", Gender.FEMALE); 		
		Client client2 = new Client (new SavingAccount(), 100.124, "Smith", Gender.MALE);
				
		//SberBank.addClient(client2); old construction
		try{
			bs.addClient(SberBank, client1);
			bs.addClient(SberBank, client2);
		}
		catch (ClientExistsException e) {
			System.out.println("The Exception" + e.getMessage() + " has occured");
		}
		
		printBalance(SberBank);	
		modifyBank(SberBank);
		printBalance(SberBank);	
		//bs.printMaximumAmountToWithdraw(SberBank);
	}

}
